package com.avicsafety.ezsystem.search;

import android.util.Log;

import com.avicsafety.ezsystem.entity.cate;
//import com.rx2androidnetworking.Rx2AndroidNetworking;

import org.json.JSONObject;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

public class MyService {


    private static final String TAG = "Service";

//    public void action(){
//        Observable.create(new ObservableOnSubscribe<String>() {
//            @Override
//            public void subscribe(@NonNull ObservableEmitter<String> e) throws Exception {
//                Log.e(TAG, "Current thread is " + Thread.currentThread().getName());
//                Log.e(TAG, "开始通过网络获取 来打开进度条");
//                e.onNext("start");
//            }
//        })
//        .subscribeOn(AndroidSchedulers.mainThread()) //打开进度条肯定是在UI线程
//        .observeOn(Schedulers.io()) // IO线程打开网络
//        .flatMap(new Function<String, ObservableSource<List<cate>>>() {
//            @Override
//            public ObservableSource<List<cate>> apply(String s)  {
//                Log.e(TAG, "Current thread is " + Thread.currentThread().getName());
//                Log.e(TAG,"访问第一个接口开始 RESTFUL对象接口");
////                return  Rx2AndroidNetworking.get("https://ps.haishengshop.com/public/goods_cate/tree")
////                        .build()
////                        .getObjectListObservable(cate.class); //获取一个json对象
//            }
//        })
//        .observeOn(AndroidSchedulers.mainThread()) // 下面的在主线程中干
//        .doOnNext(new Consumer<List<cate>>() {
//            @Override
//            public void accept(@NonNull List<cate> data){
//                Log.e(TAG, "Current thread is " + Thread.currentThread().getName());
//                Log.e(TAG, "第一次OK: doOnNext :" +data.size());
//            }
//        })
//        .observeOn(Schedulers.io())
//        .flatMap(new Function<List<cate>, ObservableSource<JSONObject>>() {
//            @Override
//            public ObservableSource<JSONObject> apply(List<cate> cates)  {
//                Log.e(TAG, "Current thread is " + Thread.currentThread().getName());
//                Log.e(TAG,"访问第二个接口开始 老的JSONOBJECT对象接口");
////                return Rx2AndroidNetworking.get("http://www.avicsafety.com/ip_search.aspx")
////                        .build()
////                        .getJSONObjectObservable(); //获取一个json对象
//            }
//        })
//        .observeOn(AndroidSchedulers.mainThread()) //切换到主线程
//        .doOnNext(new Consumer<JSONObject>() {
//            @Override
//            public void accept(@NonNull JSONObject data) {
//                Log.e(TAG, "Current thread is " + Thread.currentThread().getName());
//                Log.e(TAG, "第二次OK: doOnNext :" +data.toString());
//            }
//        })
//        .observeOn(Schedulers.io())
//        .flatMap(new Function<JSONObject, ObservableSource<String>>() {
//            @Override
//            public ObservableSource<String> apply(JSONObject obj)  {
//                Log.e(TAG, "Current thread is " + Thread.currentThread().getName());
//                Log.e(TAG,"访问第三个接口开始 字符串接口");
////                return Rx2AndroidNetworking.get("https://www.365aq.cn/")
////                        .build()
////                        .getStringObservable();
//            }
//        })
//        .observeOn(AndroidSchedulers.mainThread()) //切换到主线程
//        .subscribe(new Consumer<String>() {
//            @Override
//            public void accept(@NonNull String data) {
//                Log.e(TAG, "Current thread is " + Thread.currentThread().getName());
//                Log.e(TAG, "第三次ok: success ：");
//                Log.e(TAG, "在主线程中 关闭loading: success ：");
//            }
//        }, new Consumer<Throwable>() {
//            @Override
//            public void accept(@NonNull Throwable throwable)  {
//                Log.e(TAG, "错误 :" + throwable.getMessage());
//            }
//        });
//    }
}
